package dynamicJsonVerifyer;

import com.alibaba.fastjson.JSONObject;

import java.util.*;

public class VerifyMetadataSelecter {

    private Map<String, VerifyMetadata> verifyMetadataMap = new HashMap<>();
    private Map<String, List<String>> renewalKeyMap = new HashMap<>();
    private Map<String, Long> versionTimeMap = new HashMap<>();
    private Map<String, String> mrKeyMap = new HashMap<>();

    public void put(String metadataKey, String renewalKey, String jsonpath, JSONObject metadataJson) {
        VerifyMetadata metadata = verifyMetadataMap.get(metadataKey);
        if(metadata==null){
            metadata = new VerifyMetadata();
            verifyMetadataMap.put(metadataKey, metadata);
        }
        metadata.addSon(jsonpath, metadataJson);

        /*
         * 添加更新标识
         */
        List<String> metadataKeyList = renewalKeyMap.get(renewalKey);
        if(metadata==null){
            metadataKeyList = new ArrayList<>();
            renewalKeyMap.put(renewalKey, metadataKeyList);
        }
        metadataKeyList.add(metadataKey);

        mrKeyMap.put(metadataKey, renewalKey);
        versionTimeMap.put(renewalKey, System.currentTimeMillis());
    }

    public VerifyMetadata getMetadata(String metadataKey){
        return verifyMetadataMap.get(metadataKey);
    }

    public void clear(String renewalKey){
        //TODO
    }

    public String getRenewalKey(String metadataKey){
        return mrKeyMap.get(metadataKey);
    }

    public long getVersionTime(String renewalKey){
        return versionTimeMap.get(renewalKey);
    }
}
